﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using System.IO;

namespace Eggplant.Web.Rest.Base
{
	public class TextSerializer : IHttpSerializer
	{
		#region IHttpSerializer Members

		public object DeserializeValue(string contentType, System.IO.Stream stream, Type type)
		{
			if (type != typeof(String))
				throw new ArgumentException("Only strings can be read by a TextSerializer.", "type");

			var streamReader = new StreamReader(stream);
			return streamReader.ReadToEnd();
		}

		public void SerializeValue(string contentType, System.IO.Stream stream, object value)
		{
			if (value == null)
				return;

			var streamWriter = new StreamWriter(stream);
			streamWriter.Write(value.ToString());
			streamWriter.Flush();
		}

		#endregion
	}
}